package com.gzgs.controller;

import com.gzgs.domain.Product;
import com.gzgs.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.WebDataBinder;
import org.springframework.web.bind.annotation.InitBinder;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import java.util.Date;
import java.util.List;

/**
 * product的controller类
 */
@Controller
@RequestMapping("/product")
public class ProductController {
    @Autowired
    private ProductService productService;

    /**
     *查询所有的产品
     */
    @RequestMapping("/findAll.do")
    public ModelAndView findAll() throws Exception {
        ModelAndView mv=new ModelAndView();
        List<Product> productList = productService.findAll();
        mv.addObject("productList",productList);
        mv.setViewName("product-list1");
        return mv;
    }

    /**
     * 删除指定id商品
     */
    @RequestMapping("/deleteById.do")
    public String deleteById(String id)throws Exception{
        productService.deleteById(id);
        return "redirect:findAll.do";
    }



    /**
     * 添加产品
     */
    @RequestMapping("/save.do")
    public String saveProduct(Product product) throws Exception {
        productService.saveProduct(product);
        return "redirect:findAll.do";
    }
}
